<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-lx-complaints"></i>投诉管理</el-breadcrumb-item>
                <el-breadcrumb-item>投诉查看</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-row>
                    <el-col :span="4">
                        <div class="grid-content bg-purple">
                            <el-button type="danger" icon="el-icon-delete" class="handle-del mr10" @click="delAllSelection"
                                >批量删除</el-button
                            >
                        </div>
                    </el-col>
                    
                    <el-col :span="6">
                        <div class="grid-content bg-purple">
                            <el-input  v-model="waybill" placeholder="货运单编号" class="handle-input mr10"></el-input>
                        </div>
                    </el-col>

                    <el-col :span="6" >
                        <div class="grid-content bg-purple" style="padding-left:530px">
                            <el-button  type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                        </div>
                    </el-col>

                </el-row>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="complaints.id" label="编号" width="55" align="center"></el-table-column>
                <el-table-column prop="user_name" label="客户名称"></el-table-column>
                <el-table-column prop="complaints.waybill_number" label="货运单编号"></el-table-column>
                <el-table-column prop="complaints.complaint_content" label="投诉内容"></el-table-column>
                <el-table-column prop="complaints.complaint_date" label="投诉日期"></el-table-column>
                <el-table-column prop="complaints.dispose" label="是否处理"></el-table-column>
                <el-table-column prop="complaints.dispose_date" label="处理日期"></el-table-column>
                <el-table-column prop="complaints.dispose_result" label="处理结果"></el-table-column>
                <el-table-column prop="complaints.report" label="是否回告"></el-table-column>
                <el-table-column prop="complaints.report_date" label="回告日期"></el-table-column>
                

                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" icon="el-icon-delete" class="red" @click="handleDelete(scope.$index, scope.row)"
                            >删除</el-button
                        >
                    </template>
                </el-table-column>
            </el-table>
            <!--分页-->
            <div class="pagination">
                <el-Pagination
                    layout="total, sizes, prev, pager, next, jumper"
                    :current-page="pageparm.currentPage"
                    :page-size="5"
                    :total="pageparm.total"
                    v-bind:child-msg="pageparm"
                    :page-sizes="[1, 5, 8, 10]"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                ></el-Pagination>
            </div>
        </div>
    </div>
</template>

<script>
import Pagination from '../common/Pagination.vue';
export default {
    name: 'TopicManage',
    data() {
        return {
            categoryList: [],
            query: {
                complaints: {
                    
                    waybill_number: '',
                   
                }
            },

            // formInline: {
            //     page: 1,
            //     limit: 5
            // },

            pageparm: {
                currentPage: 1,
                pageSize: 5,
                total: 5
            },
            tableData: [],
            current: '',
            multipleSelection: [],
            delList: [],
            editVisible: false,
            id: -1,
            waybill:""
        };
    },
    created() {
        this.findCategory();
    },
    methods: {
     
        //查询所有数据
        findCategory() {
            
            this.$axios
                .post('/api/complaints/findComplaints/' + this.pageparm.currentPage + '/' + this.pageparm.pageSize,this.query)
                .then((res) => {
                    console.log(res.data.data.list);
                    if (res.data.code == 200) {
                        this.tableData = res.data.data.list;
                        this.pageparm.total = res.data.data.total;
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pageparm.pageSize = val;
            console.log(this.pageparm.pageSize);
            this.findCategory();
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.pageparm.currentPage = val;
            this.findCategory();
        },
        //条件搜索
        getData() {
           this.$axios
                .post('/api/complaints/findByWaybill/'+this.waybill,this.query)
                .then((res) => {
                    console.log(res);
                    if (res.data.code == 200) {
                        this.tableData = res.data.data;
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },

        // 触发搜索按钮
        handleSearch() {
            // this.$set(this.pageparm, 'currentPage', 1);
            
            this.getData();
        },

        // 删除操作
        handleDelete(index, row) {
            // 二次确认删除
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            })
                .then(() => {
                    this.$axios
                        .delete('/api/complaints/deleteById/' + row.complaints.id)
                        .then((res) => {
                            //console.log(res);
                            if (res.data.code == 200) {
                                this.$message({
                                    type: 'success',
                                    message: '数据已删除!'
                                });
                                //重新获取当前页面数据重新渲染列表！
                                this.getData(this.pageparm);
                            } else {
                                this.$message({
                                    type: 'info',
                                    message: res.data.msg
                                });
                            }
                        })
                        .catch((err) => {
                            //this.$message.error('数据删除失败，请稍后再试！')
                            console.log(err);
                        });
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
        },
        // 多选操作
        handleSelectionChange(val) {
            //console.log(val);
            this.multipleSelection = val;
        },
        delAllSelection() {
            // 二次确认删除
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            })
                .then(() => {
                    //console.log(this.multipleSelection);
                    const length = this.multipleSelection.length;
                    let str = '';
                    this.delList = this.delList.concat(this.multipleSelection);
                    for (let i = 0; i < length; i++) {
                        str += this.multipleSelection[i].name + ' ';
                        // console.log(this.multipleSelection[i].id);
                        this.$axios
                            .delete('/api/complaints/deleteById/' + this.multipleSelection[i].complaints.id)
                            .then((res) => {
                                //console.log(res);
                                if (res.data.code == 200) {
                                    this.$message({
                                        type: 'success',
                                        message: '数据已删除!'
                                    });
                                    //重新获取当前页面数据重新渲染列表！
                                    this.getData(this.pageparm);
                                } else {
                                    this.$message({
                                        type: 'info',
                                        message: res.data.msg
                                    });
                                }
                            })
                            .catch((err) => {
                                //this.$message.error('数据删除失败，请稍后再试！')
                                console.log(err);
                            });
                        //console.log(str);
                    }
                    this.multipleSelection = [];
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
        }
    },
    //挂子
    components: {
        Pagination
    }
};
</script>

<style scoped>

.handle-box {
    margin-bottom: 20px;
}
.el-input {
    position: relative;
    font-size: 14px;
    display: inline-block;
    width: 200px !important;
}
.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
